//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  UserCenterBoard.m
//  iHeima
//
//  Created by he chao on 5/27/14.
//  Copyright (c) 2014 leon. All rights reserved.
//

#import "UserCenterBoard.h"
#import "SettingBoard.h"
#import "MyCircleBoard.h"
#import "MyActivitiesBoard.h"
#import "MyCollectionBoard.h"

#import "myNewsBoard.h"
#import "myAskBoard.h"
#import "FeedbackBoard.h"
#pragma mark -

@interface UserCenterBoard()
{
	//<#@private var#>
}
@end

@implementation UserCenterBoard

- (void)load
{
}

- (void)unload
{
}

#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.title = @"我的";
    self.navigationController.navigationBarHidden = NO;
    [self showNaviBar];
    self.view.backgroundColor = RGB(246, 246, 246);
    [self loadContent];
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
    NSMutableDictionary *dictUser = kUserInfo;
   // [avatar setImageWithURL:[NSString stringWithFormat:@"%@avatar.php?uid=%@",kPicUrl,dictUser[@"uid"]] placeholderImage:IMAGESTRING(@"default_avatar")];
    labelName.text = dictUser[@"username"];
    
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"%@avatar.php?uid=%@",kPicUrl,kUserInfo[@"uid"]]];
   // [avatar setImageWithURL: [NSURL URLWithString:[NSString stringWithFormat:@"http://u1.iheima.com/avatar.php?uid=1"]] ];
    
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData* data  = [NSData dataWithContentsOfURL:url];
        UIImage* image = [UIImage imageWithData:data];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            avatar.image = image;
        });
    });
    
    
}




ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

- (void)loadContent{
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.viewWidth, 120)];
    header.backgroundColor = [UIColor whiteColor];
    
    avatar = [BeeUIImageView spawn];
    avatar.frame = CGRectMake(12, 20, 75, 75);
    avatar.backgroundColor = RGB(246, 246, 246);
    avatar.image = IMAGESTRING(@"my_default_avatar");
    avatar.contentMode = UIViewContentModeScaleToFill;
    [header addSubview:avatar];
    
    BeeUIImageView *imgCamera = [BeeUIImageView spawn];
    imgCamera.frame = CGRectMake(avatar.right-14, avatar.bottom-14, 22, 22);
    imgCamera.image = IMAGESTRING(@"camera");
    [header addSubview:imgCamera];
    
    labelName = [BaseLabel initLabel:@"Your Name" font:FONT(16) color:RGB(55, 55, 55) textAlignment:NSTextAlignmentLeft];
    labelName.frame = CGRectMake(avatar.right+10, avatar.top, 200, 20);
    [header addSubview:labelName];
    
//    labelId = [BaseLabel initLabel:@"Your ID" font:FONT(14) color:labelName.textColor textAlignment:NSTextAlignmentLeft];
//    labelId.frame = CGRectMake(labelName.left, labelName.bottom, 200, 20);
//    [header addSubview:labelId];
    
//    NSArray *arrayTitle = @[@"关注",@"粉丝",@"私信"];
//    for (int i = 0; i < 3; i++) {
//        BaseLabel *labelV = [BaseLabel initLabel:@"22" font:FONT(14) color:RGB(146, 146, 146) textAlignment:NSTextAlignmentCenter];
//        labelV.frame = CGRectMake(55*i+labelId.left, labelId.bottom+10, 55, 20);
//        [header addSubview:labelV];
//        
//        BaseLabel *labelT = [BaseLabel initLabel:arrayTitle[i] font:FONT(14) color:labelV.textColor textAlignment:NSTextAlignmentCenter];
//        labelT.frame = CGRectMake(labelV.left, labelV.bottom, labelV.width, labelV.height);
//        [header addSubview:labelT];
//        
//        if (i<2) {
//            BeeUIImageView *line = [BeeUIImageView spawn];
//            line.frame = CGRectMake(labelV.right, labelV.top+5, 0.5, 30);
//            line.backgroundColor = [UIColor blackColor];
//            [header addSubview:line];
//        }
//    }
    
    
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.viewWidth, self.viewHeight-60-(IOS7_OR_LATER?64:44))];
    myTableView.backgroundColor = [UIColor clearColor];
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    myTableView.delegate = self;
    myTableView.dataSource = self;
    [self.view addSubview:myTableView];
    myTableView.tableHeaderView = header;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 5;
    }
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 34;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.viewWidth, 20)];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    if (nil == cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];
        
        //[cell initSelf];
    }
    
    for (id element in cell.contentView.subviews) {
        [element removeFromSuperview];
    }
    NSString *strTitle,*strImageSource;
    if (indexPath.section == 0) {
//        NSArray *arrayT = @[@"我的活动",@"我的收藏",@"我的圈子",@"创业资讯",@"创业问答",@"创业论坛"];
        NSArray *arrayT = @[@"我的圈子",@"我的活动",@"创业资讯",@"创业问答",@"我的收藏"];
//        NSArray* arrayImage=@[@"my_activities",@"my_collection",@"my_circle",@"my_pioneerInformation",@"my_ploneerAsked",@"my_pioneerForum"];
         NSArray* arrayImage=@[@"my_circle",@"my_activities",@"my_pioneerInformation",@"my_ploneerAsked",@"my_collection"];
        strTitle = arrayT[indexPath.row];
        strImageSource = arrayImage[indexPath.row];
    }
    else {
//        strTitle = @"设置";
//        strImageSource = @"my_setting";
        
        
        NSArray* arrayS=@[@"设置",@"反馈意见"];
        NSArray* arrayPic=@[@"my_setting",@"my_ideas"];
        strTitle=arrayS[indexPath.row];
        strImageSource=arrayPic[indexPath.row];
        
        
        
    }
    cell.imageView.image = IMAGESTRING(strImageSource);
    cell.textLabel.text = strTitle;
    cell.backgroundColor = [UIColor whiteColor];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.font = [UIFont systemFontOfSize:14.0];
    
    
    
    if (indexPath.section == 0 && indexPath.row<4) {
        BeeUIImageView *line = [BeeUIImageView spawn];
        line.frame = CGRectMake(0, 33.5, self.viewWidth, 0.5);
        line.backgroundColor = RGB(187, 187, 187);
        [cell.contentView addSubview:line];
    }else{
        BeeUIImageView* lines=[BeeUIImageView spawn];
        lines.frame = CGRectMake(0, 33.5, self.viewWidth, 0.5);
        lines.backgroundColor = RGB(187, 187, 187);
        [cell.contentView addSubview:lines];
    }
    //[cell load];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                    // 我得圈子
                case 0:
                {
                    [[MainBoard sharedInstance].stack pushBoard:[[MyCircleBoard alloc] init] animated:YES];
                    
                }
                    break;
                    
                    // 我得活动
                case 1:
                {
                    
                    [[MainBoard sharedInstance].stack pushBoard:[[MyActivitiesBoard alloc] init] animated:YES];
                }
                    break;
                    //创业资讯
                case 2:
                {
                    
                    [[MainBoard sharedInstance].stack pushBoard:[[myNewsBoard alloc] init] animated:YES];
                }
                    break;
                    
                    // 创业问答
                case 3:
                {
                    
                    [[MainBoard sharedInstance].stack pushBoard:[[myAskBoard alloc]init] animated:YES];
                }
                    break;
                    // 我的收藏
                case 4:
                {
                    [[MainBoard sharedInstance].stack pushBoard:[[MyCollectionBoard alloc] init] animated:YES];
                }
                    break;
                    
                    
                default:
                    break;
            }
        }
            break;
        case 1:
        {
            
            switch (indexPath.row)
            {
                case 0:
                    [[MainBoard sharedInstance].stack pushBoard:[[SettingBoard alloc] init] animated:YES];
                    break;
                    
                case 1:
                {
                    
                    FeedbackBoard *board = [[FeedbackBoard alloc] init];
                    [self.stack pushBoard:board animated:YES];
                }
                    break;
                    
                
            }
            break;
            
        }
    }
}
@end
